package com.qigao.mall.web.controller.app.merchant;

import com.qigao.mall.api.OrderService;
import com.qigao.mall.commons.dto.MonthReportDto;
import com.qigao.mall.commons.dto.SaleMonthReportDto;
import com.qigao.mall.commons.enums.Result;
import com.qigao.mall.commons.enums.ResultCode;
import com.qigao.mall.commons.utils.DateUtil;
import com.qigao.mall.web.vo.app.MonthReportVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @author luiz
 * @Title: com.qigao.mall.web.controller.app.merchant
 * @ProjectName three-mall
 * @date 2019-12-2019/12/19 14:23
 * @Description:
 */
@RestController
@RequestMapping("/app/merchant/report/")
@Api(tags = "App商户报表相关API" ,value = "App商户报表相关API")
public class MerchantReportController {

    private static Logger logger= LoggerFactory.getLogger(MerchantReportController.class);

    @Resource
    private OrderService orderService;

    //1.每月销售汇总
    @PostMapping("/findSaleReport")
    @ApiOperation(value = "每月销售汇总", notes = "每月销售汇总")
    public Result<SaleMonthReportDto> findSaleReport(@RequestBody MonthReportVo monthReportVo, HttpServletRequest request){
        try{
            //参数校验
            if(StringUtils.isEmpty(monthReportVo.getMonthNum())){
                monthReportVo.setMonthNum(DateUtil.getDateFormat(new Date(),"yyyy-MM"));
            }
            MonthReportDto monthReportDto=new MonthReportDto();
            BeanUtils.copyProperties(monthReportVo,monthReportDto);
            return  orderService.findSaleReport(monthReportDto);
        }catch (Exception e){
            logger.error("[每月销售汇总]发生异常:{}",e);
            return Result.newError(ResultCode.FAIL);
        }
    }


}
